//
// Created by aaa on 2025/7/12.
//

#include<bits/stdc++.h>

using namespace std;
const int N = 2e5 + 10;

int n,m;
int w,v,s;
int dp[N],g[N],q[N];

//多重背包 单调队列优化
//4 5
//1 2 3
//2 4 1
//3 4 3
//4 5 2
int main(){
    cin >> n >> m;

    for(int i = 1;i <= n;i++){
        memcpy(g,dp,sizeof(dp));
        cin >> w >> v >> s;

        //拆分成w类
        for(int j = 0;j < w;j++){
            int h = 0,t = -1;

            //对每个类进行单调队列
            for(int k = j;k <= m;k += w){
                if(h <= t && q[h] < k - s * w) h++;

                //使用队头最大值更新dp
                if(h <= t) dp[k] = max(g[k],g[q[h]] + (k-q[h])/w*v);

                while(h <= t && g[k] >= g[q[t]] + (k-q[t])/w*v) t--;

                q[++t] = k;
            }

        }
    }

    cout << dp[m];

    return 0;
}